<?php 

class LoginControl extends Control
{
    /**
     * 会员登录
     * @return [type] [description]
     */
    public function login()
    {
        if(IS_POST){
            $_POST['password'] = md5($_POST['password']);
            $username = $_POST['username'];
            $password = $_POST['password'];
            $db = M('user');
            $data = $db->where("username='".$username."'")->find();
            if($data) 
            {
                if($data['password'] == $password)
                {
                    $_SESSION['user'] = array();
                    $_SESSION['user']['username'] = $data['username'];
                    $_SESSION['user']['uid'] = $data['uid'];
                    $this->success("登陆成功", q("session.history"));
                }
                $this->error('密码错误');
            }
            $this->error('用户名不存在');         
        }else{
            $this->display();
        }        
    }

    /**
     * 会员注册
     * @return [type] [description]
     */
    public function reg()
    {
        if(IS_POST){
            $_POST['password'] = md5($_POST['password']);
            $_POST['login_time'] = date(time());
            $db = M('user');
            $db ->add();
            $this->success('注册成功','login');
        }else{
          $this->display();  
        }       
    }

    /**
     * 退出登陆
     * @return [type] [description]
     */
    public function out()
    {
        $_SESSION['user'] = array();
        header("Location:".__ROOT__."/index.php");
    }



}























 ?>